﻿using System;
namespace Doc.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Document", Namespace="http://doc.x-road.eu/", Target=typeof(Document))]
    public class DocumentSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected Document clazz;
        
        public DocumentSerializer(Document clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Name");
            if (clazz.Name!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Name))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Name");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Sisu");
            if (clazz.Sisu!=null && clazz.Sisu.Exists) {
                global::Xtee.Core.MultipartSoapUtils.WriteMtomAttachment(clazz.Sisu, "Sisu", Writer, "application/octetstream");
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Name") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Document>Name");
                }
                clazz.Name = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Name")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Document>Name", Reader.LocalName);
            }
            if (Reader.LocalName=="Sisu") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Sisu = global::Xtee.Core.MultipartSoapUtils.ReadMtomAttachment("Sisu", Reader, "application/octetstream");
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Document>Sisu", Reader.LocalName);
            }
        }
    }
}
